Unit test « Development « Java I/O Q&A





1. Unit test with files system dependency - hidden files    stackoverflow.com

I am writing a "Total Commander" like application in Java. There is quite obvious file system dependency here. I want to unit test it. I created directory structure for test purposes, ...

2. Java, Junit - Capture the standard input / Output for use in a unit test    stackoverflow.com

I'm writing integration tests using JUnit to automate the testing of a console based application. The application is homework but this part isn't the homework. I want to automate these tests ...

3. Using reflection to change static final File.separatorChar for unit testing?    stackoverflow.com

Specifically, I'm trying to create a unit test for a method which requires uses File.separatorChar to build paths on windows and unix. The code must run on both platforms, and yet ...

4. Running unit tests from currently opened file in intelliJ    stackoverflow.com

Is there any way to have IntelliJ run the current MyTest.java file I'm looking at? Thanks

5. How to Unit Test File Access (Java)?    stackoverflow.com

I know that a good unit test should never access the file system. So I also know, that you can use Mockito and PowerMock for example to mock out the File ...

6. Why does this unit test say my directory doesn't exist when it does?    stackoverflow.com

This code

URL listofFiles = this.getClass().getResource("someDir");
File f = new File(listofFiles.toString());
File[] files = f.listFiles();
runs in a JUnit unit test in a Tomcat webserver environment. The URL that's returned is most definitely valid. I've gone ...

7. Starting unit tests automatically after saving a file    stackoverflow.com

With Ruby on Rails, I could use autotest, to run all my tests automatically each time, when I saved a file of my code. Additionally, the framework started only the tests ...

8. Unit testing a method that writes serialized objects to a file    stackoverflow.com

I have a static method that writes serialized object. How can I write JUnit tests to see if it works? Here is my method...

    public static void writeToDisk(Data ...

9. How do I write a unit test to cover the case where an IOException is thrown?    stackoverflow.com

I have the following class:

    public class FileLoader {   

         private Map<Brand, String> termsOfUseText = new HashMap<Brand, String>();

 ...





10. What's a good pattern for a java unit test that ensures that you are properly closing files?    stackoverflow.com

I have an issue in my codebase where we are not properly closing file handles, or probably streams. We eventually get a TooManyOpenFiles exception under very heavy load. Based ...

11. How to unit test for backward and forward compatibility?    stackoverflow.com

I am working on developing an Plug-In API that uses Java serialization. The idea is similar to SmallTalk's system images. I was wondering how would to best to automate testing for ...

12. Unit Testing serializability for all classes in java project    stackoverflow.com

I've thousands of classes in our java project. Some of them implements serializable interface. Now here's a problem. It's possible someone can go in a class, add new variable ...

13. How can I unit test classes that read input in Java?    stackoverflow.com

How is it possible to run tests against a class that reads from System.in for user input? For example:

private int getUserInput() {
    Scanner scanner = new Scanner(System.in);

   ...

14. Running file-based unit tests in an environment which does not allow access to the file system    coderanch.com

This arises from a programming exercise which a company recently sent me as part of a job recruitment process. The test was to write a Java 5 program which reads data files from a specified directory, or any sub-directories below it, reads the contents of the files, and prints summary information to the screen. The files simply contain integers (one integer ...